home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / rcs5ap1s.lzh / MERGE.SH < prev    next >
Text File  |  1991-01-10  |  2KB  |  153 lines

  1. : 'Output the merge command as a shell file.'
  2.  
  3. Id='$Id: merge.sh,v 5.3 90/11/01 05:03:32 eggert Exp $'
  4.  
  5. cat >a.sh <<'EOF' && chmod +x a.sh || exit
  6. #!/bin/sh
  7. export something
  8. EOF
  9. if
  10.     (
  11.         ./a.sh &&
  12.         if csh -c :
  13.         then csh -c ./a.sh
  14.         else :
  15.         fi
  16.     ) 2>/dev/null
  17. then
  18.     echo '#!/bin/sh'
  19.     echo '# merge - three-way file merge'
  20.     echo "#    $Id"
  21. else
  22.     echo ': merge - three-way file merge'
  23.     echo ": '$Id'"
  24. fi
  25. rm -f a.sh
  26.  
  27. cat <<EOF
  28.  
  29. DIFF=${DIFF?}
  30. DIFF3=${DIFF3?}
  31. EOF
  32.  
  33. cat <<'EOF'
  34. PATH=/bin:/usr/bin
  35. labels=0 p=w say=echo
  36. while
  37.     case $1 in
  38.     -p)
  39.         p='1,$p';;
  40.     -q)
  41.         say=:;;
  42.     -L)
  43.         case $labels in
  44.         0) l1=$2 labels=1;;
  45.         1) l3=$2 labels=2;;
  46.         *) echo "merge: too many -L options"; exit 2
  47.         esac
  48.         case $# in
  49.         1) ;;
  50.         *) shift
  51.         esac;;
  52.     -*)
  53.         echo "merge: $1: unknown option"; exit 2;;
  54.     *)
  55.         break
  56.     esac
  57. do shift
  58. done
  59.  
  60. case $# in
  61. 3) ;;
  62. *)
  63.     echo >&2 'merge: usage: merge [-p] [-q] [-L label1 [-L label3]] file1 file2 file3'
  64.     exit 2
  65. esac
  66.  
  67. f1=$1 f2=$2 f3=$3
  68. case $1 in +*) f1=./$1;; esac
  69. case $2 in +*|-*) f2=./$2;; esac
  70. case $3 in +*|-*) f3=./$3;; esac
  71.  
  72. case $labels in
  73. 0) l3=$3 l1=$1;;
  74. 1) l3=$3
  75. esac
  76.  
  77. case $p in
  78. w)
  79.     if test ! -w "$f1"
  80.     then
  81.         echo >&2 "merge: $1 not writeable"
  82.         exit 2
  83.     fi
  84. esac
  85.  
  86. status=2
  87. temps=
  88. trap '
  89.     case $temps in
  90.     ?*) rm -f $temps || status=2
  91.     esac
  92.     exit $status
  93. ' 0
  94. trap exit 1 2 3 13 15
  95. umask 077
  96.  
  97. t=/tmp/d3t$$
  98.  
  99. EOF
  100.  
  101. case ${DIFF3_TYPE?} in
  102. bin) sed 's/^[     ]*//' <<'EOF'
  103.     case $p in
  104.     w) temps=$t;;
  105.     *) t=
  106.     esac
  107.  
  108.     $DIFF3 -am -L "$l1" -L "$l3" "$f1" "$f2" "$f3" >$t
  109.     s=$?
  110.  
  111.     case $s in
  112.     0) ;;
  113.     1) $say >&2 "merge: overlaps during merge";;
  114.     *) exit
  115.     esac
  116.  
  117.     case $p in
  118.     w) cp $t "$f1" || s=2
  119.     esac
  120.  
  121.     status=$s
  122. EOF
  123. ;;
  124.  
  125. *) sed 's/^[     ]*//' <<'EOF'
  126.     temps="/tmp/d3a$$ /tmp/d3b$$ $t"
  127.  
  128.     $DIFF "$f1" "$f3" >/tmp/d3a$$
  129.     case $? in
  130.     0|1) ;;
  131.     *) exit
  132.     esac
  133.  
  134.     $DIFF "$f2" "$f3" >/tmp/d3b$$
  135.     case $? in
  136.     0|1) ;;
  137.     *) exit
  138.     esac
  139.  
  140.     $DIFF3 -E /tmp/d3a$$ /tmp/d3b$$ "$f1" "$f2" "$f3" "$l1" "$l3" >$t
  141.     s=$?
  142.  
  143.     case $s in
  144.     0) ;;
  145.     *) s=1; $say >&2 "merge: overlaps or other problems during merge"
  146.     esac
  147.  
  148.     echo $p >>$t  &&  ed - "$f1" <$t   ||   s=2
  149.  
  150.     status=$s
  151. EOF
  152. esac
  153.